home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpuintrf.h < prev    next >
C/C++ Source or Header  |  2000-05-14  |  18KB  |  574 lines

  1. #ifndef CPUINTRF_H
  2. #define CPUINTRF_H
  3.  
  4. #include "osd_cpu.h"
  5. #include "memory.h"
  6. #include "timer.h"
  7.  
  8. /* The old system is obsolete and no longer supported by the core */
  9. #define NEW_INTERRUPT_SYSTEM    1
  10.  
  11. #define MAX_IRQ_LINES   8       /* maximum number of IRQ lines per CPU */
  12.  
  13. #define CLEAR_LINE        0        /* clear (a fired, held or pulsed) line */
  14. #define ASSERT_LINE     1       /* assert an interrupt immediately */
  15. #define HOLD_LINE       2       /* hold interrupt line until enable is true */
  16. #define PULSE_LINE        3        /* pulse interrupt line for one instruction */
  17.  
  18. #define MAX_REGS        128     /* maximum number of register of any CPU */
  19.  
  20. /* Values passed to the cpu_info function of a core to retrieve information */
  21. enum {
  22.     CPU_INFO_REG,
  23.     CPU_INFO_FLAGS=MAX_REGS,
  24.     CPU_INFO_NAME,
  25.     CPU_INFO_FAMILY,
  26.     CPU_INFO_VERSION,
  27.     CPU_INFO_FILE,
  28.     CPU_INFO_CREDITS,
  29.     CPU_INFO_REG_LAYOUT,
  30.     CPU_INFO_WIN_LAYOUT
  31. };
  32.  
  33. #define CPU_IS_LE        0    /* emulated CPU is little endian */
  34. #define CPU_IS_BE        1    /* emulated CPU is big endian */
  35.  
  36. /*
  37.  * This value is passed to cpu_get_reg to retrieve the previous
  38.  * program counter value, ie. before a CPU emulation started
  39.  * to fetch opcodes and arguments for the current instrution.
  40.  */
  41. #define REG_PREVIOUSPC    -1
  42.  
  43. /*
  44.  * This value is passed to cpu_get_reg/cpu_set_reg, instead of one of
  45.  * the names from the enum a CPU core defines for it's registers,
  46.  * to get or set the contents of the memory pointed to by a stack pointer.
  47.  * You can specify the n'th element on the stack by (REG_SP_CONTENTS-n),
  48.  * ie. lower negative values. The actual element size (UINT16 or UINT32)
  49.  * depends on the CPU core.
  50.  * This is also used to replace the cpu_geturnpc() function.
  51.  */
  52. #define REG_SP_CONTENTS -2
  53.  
  54. /*
  55.  * These flags can be defined in the makefile (or project) to
  56.  * exclude (zero) or include (non zero) specific CPU cores
  57.  */
  58. #ifndef HAS_GENSYNC
  59. #define HAS_GENSYNC        0
  60. #endif
  61. #ifndef HAS_Z80
  62. #define HAS_Z80         0
  63. #endif
  64. #ifndef HAS_Z80_VM
  65. #define HAS_Z80_VM        0
  66. #endif
  67. #ifndef HAS_8080
  68. #define HAS_8080        0
  69. #endif
  70. #ifndef HAS_8085A
  71. #define HAS_8085A        0
  72. #endif
  73. #ifndef HAS_M6502
  74. #define HAS_M6502        0
  75. #endif
  76. #ifndef HAS_M65C02
  77. #define HAS_M65C02        0
  78. #endif
  79. #ifndef HAS_M65SC02
  80. #define HAS_M65SC02        0
  81. #endif
  82. #ifndef HAS_M65CE02
  83. #define HAS_M65CE02        0
  84. #endif
  85. #ifndef HAS_M6509
  86. #define HAS_M6509        0
  87. #endif
  88. #ifndef HAS_M6510
  89. #define HAS_M6510        0
  90. #endif
  91. #ifndef HAS_M6510T
  92. #define HAS_M6510T        0
  93. #endif
  94. #ifndef HAS_M7501
  95. #define HAS_M7501        0
  96. #endif
  97. #ifndef HAS_M8502
  98. #define HAS_M8502        0
  99. #endif
  100. #ifndef HAS_N2A03
  101. #define HAS_N2A03        0
  102. #endif
  103. #ifndef HAS_M4510
  104. #define HAS_M4510        0
  105. #endif
  106. #ifndef HAS_H6280
  107. #define HAS_H6280        0
  108. #endif
  109. #ifndef HAS_I86
  110. #define HAS_I86         0
  111. #endif
  112. #ifndef HAS_I88
  113. #define HAS_I88         0
  114. #endif
  115. #ifndef HAS_I186
  116. #define HAS_I186        0
  117. #endif
  118. #ifndef HAS_I188
  119. #define HAS_I188        0
  120. #endif
  121. #ifndef HAS_I286
  122. #define HAS_I286        0
  123. #endif
  124. #ifndef HAS_V20
  125. #define HAS_V20         0
  126. #endif
  127. #ifndef HAS_V30
  128. #define HAS_V30         0
  129. #endif
  130. #ifndef HAS_V33
  131. #define HAS_V33         0
  132. #endif
  133. #ifndef HAS_I8035
  134. #define HAS_I8035        0
  135. #endif
  136. #ifndef HAS_I8039
  137. #define HAS_I8039        0
  138. #endif
  139. #ifndef HAS_I8048
  140. #define HAS_I8048        0
  141. #endif
  142. #ifndef HAS_N7751
  143. #define HAS_N7751        0
  144. #endif
  145. #ifndef HAS_M6800
  146. #define HAS_M6800        0
  147. #endif
  148. #ifndef HAS_M6801
  149. #define HAS_M6801        0
  150. #endif
  151. #ifndef HAS_M6802
  152. #define HAS_M6802        0
  153. #endif
  154. #ifndef HAS_M6803
  155. #define HAS_M6803        0
  156. #endif
  157. #ifndef HAS_M6808
  158. #define HAS_M6808        0
  159. #endif
  160. #ifndef HAS_HD63701
  161. #define HAS_HD63701     0
  162. #endif
  163. #ifndef HAS_M6805
  164. #define HAS_M6805        0
  165. #endif
  166. #ifndef HAS_M68705
  167. #define HAS_M68705        0
  168. #endif
  169. #ifndef HAS_HD63705
  170. #define HAS_HD63705     0
  171. #endif
  172. #ifndef HAS_HD6309
  173. #define HAS_HD6309        0
  174. #endif
  175. #ifndef HAS_M6809
  176. #define HAS_M6809        0
  177. #endif
  178. #ifndef HAS_KONAMI
  179. #define HAS_KONAMI        0
  180. #endif
  181. #ifndef HAS_M68000
  182. #define HAS_M68000        0
  183. #endif
  184. #ifndef HAS_M68010
  185. #define HAS_M68010        0
  186. #endif
  187. #ifndef HAS_M68020
  188. #define HAS_M68020        0
  189. #endif
  190. #ifndef HAS_T11
  191. #define HAS_T11         0
  192. #endif
  193. #ifndef HAS_S2650
  194. #define HAS_S2650        0
  195. #endif
  196. #ifndef HAS_TMS34010
  197. #define HAS_TMS34010    0
  198. #endif
  199. #ifndef HAS_TMS9900
  200. #define HAS_TMS9900     0
  201. #endif
  202. #ifndef HAS_TMS9940
  203. #define HAS_TMS9940     0
  204. #endif
  205. #ifndef HAS_TMS9980
  206. #define HAS_TMS9980     0
  207. #endif
  208. #ifndef HAS_TMS9985
  209. #define HAS_TMS9985     0
  210. #endif
  211. #ifndef HAS_TMS9989
  212. #define HAS_TMS9989     0
  213. #endif
  214. #ifndef HAS_TMS9995
  215. #define HAS_TMS9995     0
  216. #endif
  217. #ifndef HAS_TMS99105A
  218. #define HAS_TMS99105A     0
  219. #endif
  220. #ifndef HAS_TMS99110A
  221. #define HAS_TMS99110A     0
  222. #endif
  223. #ifndef HAS_Z8000
  224. #define HAS_Z8000        0
  225. #endif
  226. #ifndef HAS_TMS320C10
  227. #define HAS_TMS320C10    0
  228. #endif
  229. #ifndef HAS_CCPU
  230. #define HAS_CCPU        0
  231. #endif
  232. #ifndef HAS_PDP1
  233. #define HAS_PDP1        0
  234. #endif
  235. #ifndef HAS_ADSP2100
  236. #define HAS_ADSP2100    0
  237. #endif
  238. #ifndef HAS_MIPS
  239. #define HAS_MIPS        0
  240. #endif
  241.  
  242. /* ASG 971222 -- added this generic structure */
  243. struct cpu_interface
  244. {
  245.     unsigned cpu_num;
  246.     void (*reset)(void *param);
  247.     void (*exit)(void);
  248.     int (*execute)(int cycles);
  249.     void (*burn)(int cycles);
  250.     unsigned (*get_context)(void *reg);
  251.     void (*set_context)(void *reg);
  252.     unsigned (*get_pc)(void);
  253.     void (*set_pc)(unsigned val);
  254.     unsigned (*get_sp)(void);
  255.     void (*set_sp)(unsigned val);
  256.     unsigned (*get_reg)(int regnum);
  257.     void (*set_reg)(int regnum, unsigned val);
  258.     void (*set_nmi_line)(int linestate);
  259.     void (*set_irq_line)(int irqline, int linestate);
  260.     void (*set_irq_callback)(int(*callback)(int irqline));
  261.     void (*internal_interrupt)(int type);
  262.     void (*cpu_state_save)(void *file);
  263.     void (*cpu_state_load)(void *file);
  264.     const char* (*cpu_info)(void *context,int regnum);
  265.     unsigned (*cpu_dasm)(char *buffer,unsigned pc);
  266.     unsigned num_irqs;
  267.     int default_vector;
  268.     int *icount;
  269.     double overclock;
  270.     int no_int, irq_int, nmi_int;
  271.     mem_read_handler memory_read;
  272.     mem_write_handler memory_write;
  273.     void (*set_op_base)(int pc);
  274.     int address_shift;
  275.     unsigned address_bits, endianess, align_unit, max_inst_len;
  276.     unsigned abits1, abits2, abitsmin;
  277. };
  278.  
  279. extern struct cpu_interface cpuintf[];
  280.  
  281. void cpu_init(void);
  282. void cpu_run(void);
  283.  
  284. /* optional watchdog */
  285. WRITE_HANDLER( watchdog_reset_w );
  286. READ_HANDLER( watchdog_reset_r );
  287. /* Use this function to reset the machine */
  288. void machine_reset(void);
  289. /* Use this function to reset a single CPU */
  290. void cpu_set_reset_line(int cpu,int state);
  291. /* Use this function to halt a single CPU */
  292. void cpu_set_halt_line(int cpu,int state);
  293.  
  294. /* This function returns CPUNUM current status (running or halted) */
  295. int cpu_getstatus(int cpunum);
  296. int cpu_gettotalcpu(void);
  297. int cpu_getactivecpu(void);
  298. void cpu_setactivecpu(int cpunum);
  299.  
  300. /* Returns the current program counter */
  301. unsigned cpu_get_pc(void);
  302. /* Set the current program counter */
  303. void cpu_set_pc(unsigned val);
  304.  
  305. /* Returns the current stack pointer */
  306. unsigned cpu_get_sp(void);
  307. /* Set the current stack pointer */
  308. void cpu_set_sp(unsigned val);
  309.  
  310. /* Get the active CPUs context and return it's size */
  311. unsigned cpu_get_context(void *context);
  312. /* Set the active CPUs context */
  313. void cpu_set_context(void *context);
  314.  
  315. /* Returns a specific register value (mamedbg) */
  316. unsigned cpu_get_reg(int regnum);
  317. /* Sets a specific register value (mamedbg) */
  318. void cpu_set_reg(int regnum, unsigned val);
  319.  
  320. /* Returns previous pc (start of opcode causing read/write) */
  321. /* int cpu_getpreviouspc(void); */
  322. #define cpu_getpreviouspc() cpu_get_reg(REG_PREVIOUSPC)
  323.  
  324. /* Returns the return address from the top of the stack (Z80 only) */
  325. /* int cpu_getreturnpc(void); */
  326. /* This can now be handled with a generic function */
  327. #define cpu_geturnpc() cpu_get_reg(REG_SP_CONTENTS)
  328.  
  329. int cycles_currently_ran(void);
  330. int cycles_left_to_run(void);
  331.  
  332. /* Returns the number of CPU cycles which take place in one video frame */
  333. int cpu_gettotalcycles(void);
  334. /* Returns the number of CPU cycles before the next interrupt handler call */
  335. int cpu_geticount(void);
  336. /* Returns the number of CPU cycles before the end of the current video frame */
  337. int cpu_getfcount(void);
  338. /* Returns the number of CPU cycles in one video frame */
  339. int cpu_getfperiod(void);
  340. /* Scales a given value by the ratio of fcount / fperiod */
  341. int cpu_scalebyfcount(int value);
  342. /* Returns the current scanline number */
  343. int cpu_getscanline(void);
  344. /* Returns the amount of time until a given scanline */
  345. double cpu_getscanlinetime(int scanline);
  346. /* Returns the duration of a single scanline */
  347. double cpu_getscanlineperiod(void);
  348. /* Returns the duration of a single scanline in cycles */
  349. int cpu_getscanlinecycles(void);
  350. /* Returns the number of cycles since the beginning of this frame */
  351. int cpu_getcurrentcycles(void);
  352. /* Returns the current horizontal beam position in pixels */
  353. int cpu_gethorzbeampos(void);
  354. /*
  355.   Returns the number of times the interrupt handler will be called before
  356.   the end of the current video frame. This is can be useful to interrupt
  357.   handlers to synchronize their operation. If you call this from outside
  358.   an interrupt handler, add 1 to the result, i.e. if it returns 0, it means
  359.   that the interrupt handler will be called once.
  360. */
  361. int cpu_getiloops(void);
  362.  
  363. /* Returns the current VBLANK state */
  364. int cpu_getvblank(void);
  365.  
  366. /* Returns the number of the video frame we are currently playing */
  367. int cpu_getcurrentframe(void);
  368.  
  369.  
  370. /* generate a trigger after a specific period of time */
  371. void cpu_triggertime (double duration, int trigger);
  372. /* generate a trigger now */
  373. void cpu_trigger (int trigger);
  374.  
  375. /* burn CPU cycles until a timer trigger */
  376. void cpu_spinuntil_trigger (int trigger);
  377. /* burn CPU cycles until the next interrupt */
  378. void cpu_spinuntil_int (void);
  379. /* burn CPU cycles until our timeslice is up */
  380. void cpu_spin (void);
  381. /* burn CPU cycles for a specific period of time */
  382. void cpu_spinuntil_time (double duration);
  383.  
  384. /* yield our timeslice for a specific period of time */
  385. void cpu_yielduntil_trigger (int trigger);
  386. /* yield our timeslice until the next interrupt */
  387. void cpu_yielduntil_int (void);
  388. /* yield our current timeslice */
  389. void cpu_yield (void);
  390. /* yield our timeslice for a specific period of time */
  391. void cpu_yielduntil_time (double duration);
  392.  
  393. /* set the NMI line state for a CPU, normally use PULSE_LINE */
  394. void cpu_set_nmi_line(int cpunum, int state);
  395. /* set the IRQ line state for a specific irq line of a CPU */
  396. /* normally use state HOLD_LINE, irqline 0 for first IRQ type of a cpu */
  397. void cpu_set_irq_line(int cpunum, int irqline, int state);
  398. /* this is to be called by CPU cores only! */
  399. void cpu_generate_internal_interrupt(int cpunum, int type);
  400. /* set the vector to be returned during a CPU's interrupt acknowledge cycle */
  401. void cpu_irq_line_vector_w(int cpunum, int irqline, int vector);
  402.  
  403. /* use these in your write memory/port handles to set an IRQ vector */
  404. /* offset corresponds to the irq line number here */
  405. WRITE_HANDLER( cpu_0_irq_line_vector_w );
  406. WRITE_HANDLER( cpu_1_irq_line_vector_w );
  407. WRITE_HANDLER( cpu_2_irq_line_vector_w );
  408. WRITE_HANDLER( cpu_3_irq_line_vector_w );
  409. WRITE_HANDLER( cpu_4_irq_line_vector_w );
  410. WRITE_HANDLER( cpu_5_irq_line_vector_w );
  411. WRITE_HANDLER( cpu_6_irq_line_vector_w );
  412. WRITE_HANDLER( cpu_7_irq_line_vector_w );
  413.  
  414. /* Obsolete functions: avoid to use them in new drivers if possible. */
  415.  
  416. /* cause an interrupt on a CPU */
  417. void cpu_cause_interrupt(int cpu,int type);
  418. void cpu_clear_pending_interrupts(int cpu);
  419. WRITE_HANDLER( interrupt_enable_w );
  420. WRITE_HANDLER( interrupt_vector_w );
  421. int interrupt(void);
  422. int nmi_interrupt(void);
  423. int m68_level1_irq(void);
  424. int m68_level2_irq(void);
  425. int m68_level3_irq(void);
  426. int m68_level4_irq(void);
  427. int m68_level5_irq(void);
  428. int m68_level6_irq(void);
  429. int m68_level7_irq(void);
  430. int ignore_interrupt(void);
  431.  
  432. /* CPU context access */
  433. void* cpu_getcontext (int _activecpu);
  434. int cpu_is_saving_context(int _activecpu);
  435.  
  436. /***************************************************************************
  437.  * Get information for the currently active CPU
  438.  * cputype is a value from the CPU enum in driver.h
  439.  ***************************************************************************/
  440. /* Return number of address bits */
  441. unsigned cpu_address_bits(void);
  442. /* Return address mask */
  443. unsigned cpu_address_mask(void);
  444. /* Return address shift factor (TMS34010 bit addressing mode) */
  445. int cpu_address_shift(void);
  446. /* Return endianess of the emulated CPU (CPU_IS_LE or CPU_IS_BE) */
  447. unsigned cpu_endianess(void);
  448. /* Return opcode align unit (1 byte, 2 word, 4 dword) */
  449. unsigned cpu_align_unit(void);
  450. /* Return maximum instruction length */
  451. unsigned cpu_max_inst_len(void);
  452.  
  453. /* Return name of the active CPU */
  454. const char *cpu_name(void);
  455. /* Return family name of the active CPU */
  456. const char *cpu_core_family(void);
  457. /* Return core version of the active CPU */
  458. const char *cpu_core_version(void);
  459. /* Return core filename of the active CPU */
  460. const char *cpu_core_file(void);
  461. /* Return credits info for of the active CPU */
  462. const char *cpu_core_credits(void);
  463. /* Return register layout definition for the active CPU */
  464. const char *cpu_reg_layout(void);
  465. /* Return (debugger) window layout definition for the active CPU */
  466. const char *cpu_win_layout(void);
  467.  
  468. /* Disassemble an instruction at PC into the given buffer */
  469. unsigned cpu_dasm(char *buffer, unsigned pc);
  470. /* Return a string describing the currently set flag (status) bits of the active CPU */
  471. const char *cpu_flags(void);
  472. /* Return a string with a register name and hex value for the active CPU */
  473. /* regnum is a value defined in the CPU cores header files */
  474. const char *cpu_dump_reg(int regnum);
  475. /* Return a string describing the active CPUs current state */
  476. const char *cpu_dump_state(void);
  477.  
  478. /***************************************************************************
  479.  * Get information for a specific CPU type
  480.  * cputype is a value from the CPU enum in driver.h
  481.  ***************************************************************************/
  482. /* Return address shift factor */
  483. /* TMS320C10 -1: word addressing mode, TMS34010 3: bit addressing mode */
  484. int cputype_address_shift(int cputype);
  485. /* Return number of address bits */
  486. unsigned cputype_address_bits(int cputype);
  487. /* Return address mask */
  488. unsigned cputype_address_mask(int cputype);
  489. /* Return endianess of the emulated CPU (CPU_IS_LE or CPU_IS_BE) */
  490. unsigned cputype_endianess(int cputype);
  491. /* Return opcode align unit (1 byte, 2 word, 4 dword) */
  492. unsigned cputype_align_unit(int cputype);
  493. /* Return maximum instruction length */
  494. unsigned cputype_max_inst_len(int cputype);
  495.  
  496. /* Return name of the CPU */
  497. const char *cputype_name(int cputype);
  498. /* Return family name of the CPU */
  499. const char *cputype_core_family(int cputype);
  500. /* Return core version number of the CPU */
  501. const char *cputype_core_version(int cputype);
  502. /* Return core filename of the CPU */
  503. const char *cputype_core_file(int cputype);
  504. /* Return credits for the CPU core */
  505. const char *cputype_core_credits(int cputype);
  506. /* Return register layout definition for the CPU core */
  507. const char *cputype_reg_layout(int cputype);
  508. /* Return (debugger) window layout definition for the CPU core */
  509. const char *cputype_win_layout(int cputype);
  510.  
  511. /***************************************************************************
  512.  * Get (or set) information for a numbered CPU of the running machine
  513.  * cpunum is a value between 0 and cpu_gettotalcpu() - 1
  514.  ***************************************************************************/
  515. /* Return number of address bits */
  516. unsigned cpunum_address_bits(int cputype);
  517. /* Return address mask */
  518. unsigned cpunum_address_mask(int cputype);
  519. /* Return endianess of the emulated CPU (CPU_LSB_FIRST or CPU_MSB_FIRST) */
  520. unsigned cpunum_endianess(int cputype);
  521. /* Return opcode align unit (1 byte, 2 word, 4 dword) */
  522. unsigned cpunum_align_unit(int cputype);
  523. /* Return maximum instruction length */
  524. unsigned cpunum_max_inst_len(int cputype);
  525.  
  526. /* Get a register value for the specified CPU number of the running machine */
  527. unsigned cpunum_get_reg(int cpunum, int regnum);
  528. /* Set a register value for the specified CPU number of the running machine */
  529. void cpunum_set_reg(int cpunum, int regnum, unsigned val);
  530.  
  531. /* Return (debugger) register layout definition for the CPU core */
  532. const char *cpunum_reg_layout(int cpunum);
  533. /* Return (debugger) window layout definition for the CPU core */
  534. const char *cpunum_win_layout(int cpunum);
  535.  
  536. unsigned cpunum_dasm(int cpunum,char *buffer,unsigned pc);
  537. /* Return a string describing the currently set flag (status) bits of the CPU */
  538. const char *cpunum_flags(int cpunum);
  539. /* Return a string with a register name and value */
  540. /* regnum is a value defined in the CPU cores header files */
  541. const char *cpunum_dump_reg(int cpunum, int regnum);
  542. /* Return a string describing the CPUs current state */
  543. const char *cpunum_dump_state(int cpunum);
  544. /* Return a name for the specified cpu number */
  545. const char *cpunum_name(int cpunum);
  546. /* Return a family name for the specified cpu number */
  547. const char *cpunum_core_family(int cpunum);
  548. /* Return a version for the specified cpu number */
  549. const char *cpunum_core_version(int cpunum);
  550. /* Return a the source filename for the specified cpu number */
  551. const char *cpunum_core_file(int cpunum);
  552. /* Return a the credits for the specified cpu number */
  553. const char *cpunum_core_credits(int cpunum);
  554.  
  555. /* Dump all of the running machines CPUs state to stderr */
  556. void cpu_dump_states(void);
  557.  
  558. /* daisy-chain link */
  559. typedef struct {
  560.     void (*reset)(int);             /* reset callback     */
  561.     int  (*interrupt_entry)(int);   /* entry callback     */
  562.     void (*interrupt_reti)(int);    /* reti callback      */
  563.     int irq_param;                  /* callback paramater */
  564. }    Z80_DaisyChain;
  565.  
  566. #define Z80_MAXDAISY    4        /* maximum of daisy chan device */
  567.  
  568. #define Z80_INT_REQ     0x01    /* interrupt request mask       */
  569. #define Z80_INT_IEO     0x02    /* interrupt disable mask(IEO)  */
  570.  
  571. #define Z80_VECTOR(device,state) (((device)<<8)|(state))
  572.  
  573. #endif    /* CPUINTRF_H */
  574.